<template>
    <div id="myCharts" ref="myCharts" style="height: 300px;width: 100%;background-color: #FFF;text-align: center;border-radius: 5px"></div>
</template>

<script>
  // 引入基本模板
  let echarts = require('echarts/lib/echarts')
  // 引入柱状图组件
  require('echarts/lib/chart/bar')
  // 引入提示框和title组件
  require('echarts/lib/component/tooltip')
  require('echarts/lib/component/title')
    export default {
        name: "MyEchart",
      props:{
        title:Array,//底部标题，例：[标题1，标题2,标题3]
        data:Array,//表数据，例：[10,20,30]

      },
      mounted(){

          this.init()
      },
      watch:{
        data(){
          this.init()
        },
      },
      methods:{
          init(){
            const  myCharts = echarts.init(this.$refs.myCharts);
            // app.title = '坐标轴刻度与标签对齐';

            let options = {
              color: ['#3398DB'],
              tooltip : {
                trigger: 'axis',
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                  type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
              },
              grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
              },
              xAxis : [
                {
                  type : 'category',
                  data : this.title,
                  axisTick: {
                    alignWithLabel: true
                  }
                }
              ],
              yAxis : [
                {
                  type : 'value'
                }
              ],
              series : [
                {
                  name:'收入',
                  type:'bar',
                  barWidth: '60%',
                  data:this.data
                }
              ]
            };
            myCharts.setOption(options);
          }
      }
    }
</script>

<style scoped>

</style>
